import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
//修改1
public class GoldMountain {

    /**
     * 金矿名称
     */
    private String name;
    /**
     * 储量
     */
    private Integer reserves;
    /**
     * 完全挖掘需要工人数
     */
    private Integer workers;

    private Integer workerUnit;

    public GoldMountain(String name, Integer reserves, Integer workers) {
        this.name = name;
        this.reserves = reserves;
        this.workers = workers;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getReserves() {
        return reserves;
    }

    public void setReserves(Integer reserves) {
        this.reserves = reserves;
    }

    public Integer getWorkers() {
        return workers;
    }

    public void setWorkers(Integer workers) {
        this.workers = workers;
    }

    public Integer getWorkerUnit() {
        return workerUnit;
    }

    public void setWorkerUnit(Integer workerUnit) {
        this.workerUnit = workerUnit;
    }

    @Override
    public String toString() {
        return "GoldMountain{" +
                "name='" + name + '\'' +
                ", reserves=" + reserves +
                ", workers=" + workers +
                ", workerUnit=" + workerUnit +
                '}';
    }
}


class TestGoldMountain {

    public static void main(String[] args) {
        //初始化5座金山
        GoldMountain a = new GoldMountain("A", 500, 5);
        GoldMountain b = new GoldMountain("B", 400, 4);
        GoldMountain c = new GoldMountain("C", 300, 4);
        GoldMountain d = new GoldMountain("D", 200, 3);
        GoldMountain e = new GoldMountain("E", 100, 2);
        List<GoldMountain> goldMountains = new ArrayList<GoldMountain>();
        goldMountains.add(a);
        goldMountains.add(b);
        goldMountains.add(c);
        goldMountains.add(d);
        goldMountains.add(e);
        Integer workerNum = 10;
        getMostGold(goldMountains, workerNum);
    }

    /**
     * @param goldMountainList 所有的金山
     * @param workerNum        工人总数
     *                         获取最多的金子
     */
    private static void getMostGold(List<GoldMountain> goldMountainList, Integer workerNum) {
        if (goldMountainList.isEmpty() || workerNum == null) {
            throw new RuntimeException("金矿山或工人数量不能为空");
        }
        //计算金山的单位工人挖掘量  (i.getReserves()/i.getWorkers())
        for (GoldMountain goldMountain : goldMountainList) {
            Integer reserves = goldMountain.getReserves();
            Integer workers = goldMountain.getWorkers();
            Integer workerUnit = reserves / workers;
            goldMountain.setWorkerUnit(workerUnit);
        }
        //根据单位工人挖掘量排序，把最多的人分配到单位挖掘量最高的金山
        GoldMountain goldMountain = goldMountainList.stream().max(Comparator.comparing(GoldMountain::getWorkerUnit)).orElse(null);
        System.out.println(goldMountain);
    }
}